﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.DAL;
using rock.Model;
using rock.UI.common;

namespace rock.UI.baseinfo
{
    public partial class FormFeeConfigUpdate : Form
    {
        DalFEE_TYPE dalFEE_TYPE = new DalFEE_TYPE();
        ModelFEE_TYPE modelFEE_TYPE = new ModelFEE_TYPE();

        public ModelFEE_TYPE _ModelFEE_TYPE 
        
        {
            get {
                return this.modelFEE_TYPE;
            }
            set {

                this.modelFEE_TYPE = value;
            }
        
        }


        public FormFeeConfigUpdate()
        {
            InitializeComponent();
            this.AcceptButton = this.button1;
            this.CancelButton = this.button2;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.WindowState = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = global::rock.Properties.Resources.house;
        }

        private void FormFeeConfig_Load(object sender, EventArgs e)
        {
            this.textBox1Name.Text = this._ModelFEE_TYPE.NAME;
            this.textBox2Size.Text = this._ModelFEE_TYPE.FEE+"";
            //List<ComboBoxInfo> infos = new List<ComboBoxInfo>();
           
            //infos.Add(new ComboBoxInfo{Id=Constant.FEE_TYPE_COUNT+"" , Name = "按使用量"});
            //infos.Add(new ComboBoxInfo { Id = Constant.FEE_TYPE_SIZE + "", Name = "按面积" });
            //infos.Add(new ComboBoxInfo { Id = Constant.FEE_TYPE_ANCHI + "", Name = "按户" });
            this.comboBox1Type.DataSource = Constant.FEE_FEE_TYPE_LIST;
            this.comboBox1Type.DisplayMember = "Name";
            this.comboBox1Type.ValueMember = "Id";
            if (this.dalFEE_TYPE.Exists(_ModelFEE_TYPE.SEQID))
            {
                this.comboBox1Type.SelectedValue = this._ModelFEE_TYPE.FEE_MODEL + "";
            }
             
        }
        private Boolean check() {
            try
            {
                StringUtils.checkText(this.textBox1Name.Text, 2, 30, "费用名称");
                StringUtils.checkIsDecimal(this.textBox2Size.Text, "计费标准");
               
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "提示");
                return false;
            }
            return true;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (!check())
            {
                return;
            }

            
            this._ModelFEE_TYPE.NAME = this.textBox1Name.Text;
            this._ModelFEE_TYPE.FEE = Convert.ToDecimal(this.textBox2Size.Text);
            this._ModelFEE_TYPE.FEE_MODEL = Convert.ToInt32(this.comboBox1Type.SelectedValue);


            if (this.dalFEE_TYPE.Exists(_ModelFEE_TYPE.SEQID ))
            {
                dalFEE_TYPE.Update(_ModelFEE_TYPE);
            }
            else
            {
                dalFEE_TYPE.Add(_ModelFEE_TYPE);
            }
            this.Close();
            //触发代理
            oneRefreshParentData();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //代理
        public delegate void RefreshParentData();
        public RefreshParentData oneRefreshParentData;
    }
}
